package com.wonders.frame.controller.core;

import com.gcr.server.response.Response;
import com.wonders.frame.common.Enum.ResponseCodeEnum;
import com.wonders.frame.common.QueryForm;
import com.wonders.frame.core.entity.EntityTemplate;
import com.wonders.frame.service.Core.CoreCurdService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

public abstract class CoreController<T extends EntityTemplate> extends AbstractController{
    protected abstract CoreCurdService getService();

    @RequestMapping("getList")
    public Response getListByParams(@RequestBody QueryForm form, HttpServletRequest request){
        return getResponseWithoutMsg(getService().findAllByParams(form, request), ResponseCodeEnum.SUCCESS.getCode());
    }

    @RequestMapping("getListNoRequest")
    public Response getListByParamsNoRequest(@RequestBody QueryForm form){
        return getResponseWithoutMsg(getService().findAllByParams(form), ResponseCodeEnum.SUCCESS.getCode());
    }

    @RequestMapping("getOne")
    public Response getOne(String id){
        return getResponseWithoutMsg(getService().findById(id), ResponseCodeEnum.SUCCESS.getCode());
    }


    @RequestMapping("delete")
    public Response delete(String id){
        getService().deleteById(id);
        return getResponseWithCode(ResponseCodeEnum.SUCCESS.getCode());
    }


}
